package thefirst.mypage.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import thefirst.LessonBoard.model.LessonBoardDao;
import thefirst.LessonBoard.model.LessonBoardVO;
import thefirst.member.model.MemberVO;
import thefirst.member.model.StudentVO;
import thefirst.member.model.TeacherVO;


@Service
public class SelectedListServiceImpl implements SelectedListService {
	@Resource(name="studentTeacherListDaoImpl")
	private SelectedListDao studentTeacherListDao;	
	@Resource(name="teacherLessonListDaoImpl")
	private SelectedListDao teacherLessonListDao;
	@Resource(name="lessonBoardDaoImpl")
	private LessonBoardDao lessonBoardDao;
	
	@Override
	public Map showSelectedListVO(MemberVO mvo)
			throws Exception {
		//뷰화면에서 넘어오는 리스트들의 키값에 맞추어 알맞은 리스트를 출력한다.
		
		HashMap m = new HashMap();
		
		List<SelectedListVO> stList = studentTeacherListDao.showSelectedListVO(mvo);
		m.put("s", stList);
		System.out.println("SelectedListServiceImpl"+stList);
		
		/*List<SelectedListVO> tlList = teacherLessonListDao.showSelectedListVO(mvo);
		m.put("t", tlList);*/
		
		int numofstList = studentTeacherListDao.countMember_st(mvo);
		m.put("snum", numofstList);
		System.out.println("showSelectedListVO:"+numofstList);
		/*int numoftlList = teacherLessonListDao.countMember_st(mvo);
		m.put("tnum", numoftlList);*/
		
		return m;
	}

	@Override
	public Map switchSelectedList(MemberVO mvo, String listtype) throws Exception {
		// TODO Auto-generated method stub
		HashMap m = new HashMap();
		
		if(listtype.equals("t")){
			List<SelectedListVO> tlList = teacherLessonListDao.showSelectedListVO(mvo);
			m.put("t", tlList);
			int numoftlList = teacherLessonListDao.countMember_st(mvo);
			m.put("tnum", numoftlList);
		}else{
			List<SelectedListVO> stList = studentTeacherListDao.showSelectedListVO(mvo);
			m.put("s", stList);
			int numofstList = studentTeacherListDao.countMember_st(mvo);
			m.put("snum", numofstList);
		}
	
		return m;
	}

	@Override
	public void registerSelectedList(String id,int lessonno, String listtype)
			throws Exception {
		// TODO Auto-generated method stub
		if(listtype.equals("s")){
			
		}else{
			TeacherVO tvo = new TeacherVO();
			tvo.setId(id);
			LessonBoardVO lbvo = new LessonBoardVO();
			lbvo.setLessonno(lessonno);
			TeacherLessonListVO tllvo = new TeacherLessonListVO();
			tllvo.setTeacherVO(tvo);
			tllvo.setLessonVO(lbvo);
			teacherLessonListDao.registerSelectedListVO(tllvo);
			
		}
	}
	
	@Override
	public void registerSelectedList(String studentid, String teacherid,
			String listtype) throws Exception {
		// TODO Auto-generated method stub
		if(listtype.equals("s")){
			StudentVO svo = new StudentVO();
			svo.setId(studentid);
			TeacherVO tvo = new TeacherVO();
			tvo.setId(teacherid);
			StudentTeacherListVO stlvo = new StudentTeacherListVO();
			stlvo.setStudentVO(svo);
			stlvo.setTeacherVO(tvo);
			studentTeacherListDao.registerSelectedListVO(stlvo);
		}
	}
	
	@Override
	public List getSelectedList(String id,String listtype) throws Exception {
		List list=null;
		if(listtype.equals("s")){
			list=studentTeacherListDao.getSelectedList(id);
		}else{
			list=teacherLessonListDao.getSelectedList(id);
		}
		return list;
	}

	@Override
	public void deleteSelectedListVO(String id,String listtype) throws Exception {
		// TODO Auto-generated method stub
		if(listtype.equals("s")){
			studentTeacherListDao.deleteSelectedListVO(id);
		}else{
			teacherLessonListDao.deleteSelectedListVO(id);
		}
	}

	
	
	
}
